package gui.tables;

import java.sql.SQLException;
import java.util.Vector;

import gui.abstracts.AbstractTable;
import gui.tables.models.MyTableModel;

import javax.swing.DefaultListSelectionModel;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;

import bean.GroupBean;

import dao.GroupDAO;
import dao.UniversityDAO;

public class TableGroup extends AbstractTable {

	private ListSelectionModel tableDefaultListSelection;
	private String[] columns = { "ID", "denumire", "anul crearii" };

	public TableGroup() {
		tableDefaultListSelection = this.getSelectionModel();
		tableMOdel = new MyTableModel();
		tableMOdel.addColumn(columns[0]);
		tableMOdel.addColumn(columns[1]);
		tableMOdel.addColumn(columns[2]);

		this.setModel(tableMOdel);

		tableDefaultListSelection.addListSelectionListener(new SelecLisner());
	}

	public void insertRowInTable() {
		tableMOdel.insertRow(this.getRowCount(), new Object[] { "", "" });
		((MyTableModel) tableMOdel).setLastRow(this.getRowCount() - 1);
		((MyTableModel) tableMOdel).setInsertNewRow(true);

		super.isSelectedOne = true;
		selectedRow = this.getRowCount() - 1;
		this.clearSelection();

	}



	private void setRowAllovedSelection() {
		if (isSelectedOne) {
			this.setRowSelectionInterval(selectedRow, selectedRow);
		}
	}

	private final class SelecLisner implements ListSelectionListener {
		public void valueChanged(ListSelectionEvent e) {
			setRowAllovedSelection();
		}

	}

}
